class BottledWater(object):
    objpool = dict()#记录生成对象
    
    def show(self, color):#显示一下颜色
        print(self.name,'颜色',color)

    def __new__(cls, type):# 使用new 初始化在实例化之前
        obj_ = cls.objpool.get(type, None)#没有找到对象就实例化
        if obj_ == None:
            obj_ = object.__new__(cls)
            cls.objpool[type] = obj_
            obj_.name = type
        return obj_

t1 = BottledWater("矿泉水")
t1.show('红色')
t2 = BottledWater("矿泉水")
t2.show('蓝色')
t3 = BottledWater("矿泉水")
t3.show('绿色')
print('\n')
t1_ = BottledWater("冰红茶")
t1_.show('红色')
t2_ = BottledWater("冰红茶")
t2_.show('蓝色')
t3_ = BottledWater("冰红茶")
t3_.show('绿色')

print('对象一共有：',len(BottledWater.objpool))
